var gObj = {//全局命名空间
    logout: function (){//退出平台
        sessionStorage.setItem("isAuthenticated","false");
        $("#user_message").css("display","none");
        $("#left_nav").css("display","none");
        $("#right_content").css("width","100%");
        location.href = "/#/login";
    }
};

var deleteObjNull = function(data){
    for(var i in data){
        //if(data.hasOwnProperty(i)){
            if(data[i] == null)delete data[i];
        //}
    }
    return data;
};
$(window).bind('hashchange', function() {
    if(location.hash == "#/login" || location.hash == "" || location.hash == "#/"){
        //sessionStorage.removeItem("leftMenuData");
        $("#right_content").css("width","100%");
        $(".left-nav").css("display","none");
        $("#menu_control_display").css("display","none");
        $("#user_message").css("display","none");
    }
});

if(!(location.hash == "#/login" || location.hash == "" || location.hash == "#/")){
    document.addEventListener("DOMContentLoaded",function(){
        $("#user_message").css("display","block");//显示用户信息
    },false);
}
(function(w){
    var leftMenu = function(){
        this.init();
    }, c,hidden = false;
    leftMenu.prototype = {
        init: function(){
            c = this;
            var leftData = sessionStorage.getItem("leftMenuData");
            if(leftData && !(location.hash == "#/login" || location.hash == "")){
                setTimeout(function(){
                    c.paint(JSON.parse(leftData));
                },400);
            }
            this.evt();
        },
        paint: function(data){
            var html = "",targetId = "";
            $("#menu_list").html("");
            data.forEach(function(item){
                if(item.parentID == 0){
                    if(item.menuOrder == 0){
                        html = "<li><a href="+item.pagePath+"><span class='"+item.menuClass+"'></span> "+item.menuName+"</a></li>";
                    }else{
                        targetId = "#"+item.sys_menuID;
                        html = "<li class='admin-parent'><a class='am-cf' data-am-collapse={target:'"+targetId+"'}><span class='"+item.menuClass+"'></span> "+item.menuName+"<span class='am-icon-angle-right am-fr am-margin-right'></span></a>"+
                            "<ul class='am-list admin-sidebar-sub am-collapse' id="+item.sys_menuID+"></ul></li>";
                    }
                    $("#menu_list").append(html);
                }else{
                    if(item.meuType == 1){
                        targetId = "#"+item.sys_menuID;
                        html = "<li class='admin-parent'><a class='am-cf' data-am-collapse={target:'"+targetId+"'}><span class='"+item.menuClass+"'></span> "+item.menuName+"<span class='am-icon-angle-right am-fr am-margin-right'></span></a>"+
                            "<ul class='am-list admin-sidebar-sub am-collapse' id="+item.sys_menuID+"></ul></li>";
                        $("#"+item.parentID).append(html);
                    }else{
                        html = "<li class = 'menu-list'><a href="+item.pagePath+"><span class='"+item.menuClass+"'></span> "+item.menuName+"</a></li>";
                        $("#"+item.parentID).append(html);
                    }
                }
            });
            setTimeout(function(){
                if(!(location.hash == "#/login" || location.hash == "" || location.hash == "#/")){
                    $("#left_nav").css("display","block");
                    //var h = (document.body.offsetWidth - $("#left_nav")[0].offsetWidth - 17)+"px";
                    $("#right_content").css("width","84%");//保证界面右边宽度
                }
            },300);
        },
        evt: function(){
            $(document).on("click","#menu_list .menu-list",function(){
                $("#menu_list .menu-list").css("background","#fff");
                $(this).css("background","#f8f8f8");
            });

            $(document).on("click","#menu_control_display",function(){
                if(!hidden){
                    hidden = true;
                    $("#left_nav").css("display","none");
                    $("#right_content").css("width","100%");
                    $(this).css("transform","rotate(180deg)");
                }else{
                    hidden = false;
                    $("#left_nav").css("display","block");
                    $("#right_content").css("width","84%");
                    $(this).css("transform","rotate(0deg)");
                }
            });
        }
    };
    gObj.leftMenu = leftMenu;
}(window));
gObj.leftObj = new gObj.leftMenu();